/**
 * 用户信息相关API
 */

/**
 * 根据用户ID查询用户信息
 * @param userid 用户ID
 * @returns Promise<UniApp.RequestSuccessCallbackResult>
 */
export const queryUserInfoById = (userid: number): Promise<UniApp.RequestSuccessCallbackResult> => {
  const token = uni.getStorageSync('token')
  return uni.request({
    url: '/api/userform/querybyuserId',
    method: 'POST',
    data: { userid },
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
      token: token,
    },
  })
}

/**
 * 新增用户信息
 * @param userInform 用户个人信息
 * @returns Promise<UniApp.RequestSuccessCallbackResult>
 */
export const addUserInfo = (userInform: {
  id?: number
  userId?: number
  username?: string
  gender?: number
  school?: string
  zhuanye?: string
  phone?: string
  unionid?: string
  country?: string
  province?: string
  city?: string
  language?: string
  wechat?: string
}): Promise<UniApp.RequestSuccessCallbackResult> => {
  const token = uni.getStorageSync('token')
  return uni.request({
    url: '/api/userform/add',
    method: 'POST',
    data: userInform,
    header: {
      'Content-Type': 'application/json',
      token: token,
    },
  })
}

/**
 * 更新用户个人信息
 * @param userInform 用户个人信息
 * @returns Promise<UniApp.RequestSuccessCallbackResult>
 */
export const updateUserProfile = (userInform: {
  id?: number
  userId?: number
  username?: string
  gender?: number
  school?: string
  zhuanye?: string
  phone?: string
  unionid?: string
  country?: string
  province?: string
  city?: string
  language?: string
  wechat?: string
}): Promise<UniApp.RequestSuccessCallbackResult> => {
  const token = uni.getStorageSync('token')
  return uni.request({
    url: '/api/userform/update',
    method: 'POST',
    data: userInform,
    header: {
      'Content-Type': 'application/json',
      token: token,
    },
  })
}
